package com.kangyi.app.controller;

import com.kangyi.app.service.NursingHomeReviewService;
import com.kangyi.dto.NursingHomeReviewDTO;
import com.kangyi.dto.ReviewPageQueryDTO;
import com.kangyi.result.PageResult;
import com.kangyi.result.Result;
import com.kangyi.vo.NursingHomeReviewListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@RestController
@RequestMapping("/app/review")
@Api(tags = "评论相关接口")
@Slf4j
public class ReviewController {

    @Autowired
    private NursingHomeReviewService nursingHomeReviewService;

    @GetMapping("/list")
    @ApiOperation("评论区分页查询")
    public Result<PageResult> pageReview(ReviewPageQueryDTO reviewPageQueryDTO){
        log.info("评论区分页查询:{}",reviewPageQueryDTO);
        try {
            PageResult pageResult = nursingHomeReviewService.list(reviewPageQueryDTO);
            return Result.success(pageResult,"查询成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/release")
    @ApiOperation("发表评论")
    @CacheEvict(cacheNames = "review_" ,allEntries = true)
    public Result releaseReview(@RequestBody NursingHomeReviewDTO nursingHomeReviewDTO){
        log.info("发表评论：{}",nursingHomeReviewDTO);
        try {
            nursingHomeReviewService.releaseReview(nursingHomeReviewDTO);
            return Result.success("发表成功!");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
